package cn.org.dian.easycommunicate.util;

import android.util.Log;

import com.google.api.translate.Language;
import com.google.api.translate.Translate;

/**
 * 
 * @author LiuGen
 * @date 2011-1-24
 */
public class GoogleTranslateService {

    private static final String TAG = "GoogleTranslateService";

    // private static final String REPLACE_QUOTE = "&#39;";

    private static final String HTTP_REFERRER = "www.dian.org.cn";

    static {

        Translate.setHttpReferrer(HTTP_REFERRER);
    }

    /**
     * make sure network is available before call
     * 
     * @param target
     * @param fromLanguageIndex
     * @param toLanguageIndex
     * @return
     * @throws Exception
     *             if remote service error
     */
    public static String translate(String target, Language fromLanguage,
            Language toLanguage) throws Exception {
        String result = null;
        result = Translate.execute(target, fromLanguage, toLanguage);

        Log.d(TAG, "result: " + result);
        // handle '
        // if (result.contains(REPLACE_QUOTE)) {

        // result = result.replaceAll(REPLACE_QUOTE, "'");

        // }
        return result;

    }
}
